home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wsc4c21.zip / TERM.C < prev    next >
C/C++ Source or Header  |  1997-06-01  |  20KB  |  676 lines

  1. /*
  2. **  TERM.C
  3. **
  4. **  Terminal emulator example program.
  5. **  Feature Dialing, XMODEM & YMODEM, and ANSI emulation.
  6. */
  7.  
  8. #define USECOMM
  9.  
  10. #include <windows.h>
  11.  
  12. #ifdef WIN32
  13. #define USE_INS HINSTANCE
  14. #define USE_PTR PSTR
  15. #else
  16. #define USE_INS HANDLE
  17. #define USE_PTR LPSTR
  18. #endif
  19.  
  20. #include "wsc.h"
  21. #include "mio.h"
  22. #include "xydriver.h"
  23. #include "term.h"
  24. #include "message.h"
  25. #include "ascii.h"
  26. #include "config.h"
  27. #include "paint.h"
  28. #include "line.h"
  29. #include "menu.h"
  30. #include "about.h"
  31. #include "sioerror.h"
  32. #include "accept.h"
  33. #include "ansi.h"
  34.  
  35. /* defines */
  36.  
  37. #define MENU_BAR_LINE    0
  38. #define MENU_BAR_CHANGE  1
  39. #define MENU_BAR_DIAL    2
  40. #define MENU_BAR_SEND    3
  41. #define MENU_BAR_RECEIVE 4
  42. #define MENU_BAR_BREAK   5
  43. #define MENU_BAR_STATUS  6
  44.  
  45. #define Dial_1   1
  46. #define Dial_2   2
  47. #define Dial_3   3
  48.  
  49. #define XM_RCV   1
  50. #define XM_SND   2
  51. #define YM_RCV   3
  52. #define YM_SND   4
  53. #define XY_MODEM 5
  54.  
  55. /* public globals */
  56.  
  57. HWND hMainWnd;            /* main window handle */
  58. HWND hInfoWnd;            /* popup handle */
  59. USE_INS hInstance;        /* program instance */
  60. int OnLineFlag = FALSE;   /* TRUE: online */
  61. int FatalFlag = FALSE;    /* TRUE: fatal error */
  62. char Temp[1024];
  63. char MsgBuffer[81];
  64.  
  65. /* private globals */
  66.  
  67. static int ThePort = -1;       /* the port */
  68. static int DebugLevel = 0;     /* debug level must be [0,1,2] */
  69. #ifdef WIN32
  70. #else
  71. static FARPROC lpfnAboutDlgProc = NULL;
  72. static FARPROC lpfnAcceptDlgProc = NULL;
  73. #endif
  74. static int WinWidth = 8 * NCOLS;
  75. static int WinHeight = 12 * NROWS + 48;
  76. static char FileName[65];
  77. static char DialString[40];
  78.  
  79. /* miscellaneous functions */
  80.  
  81. int StartXY(int,LPSTR);
  82. void ErrorCheck(int);
  83. void ErrorMessage(LPSTR);
  84. void ShowProgress(void);
  85.  
  86. #ifdef WIN32
  87. int WINAPI
  88. #else
  89. int PASCAL
  90. #endif
  91. WinMain(USE_INS hInst,USE_INS hPrevInstance,USE_PTR lpCmdLine,int nCmdShow)
  92. {WNDCLASS  wc;
  93.  MSG msg;
  94.  BOOL Result;
  95.  if(!hPrevInstance)
  96.    {/* register main window class */
  97.     wc.style = CS_HREDRAW | CS_VREDRAW;
  98.     wc.lpfnWndProc = MainWndProc;
  99.     wc.cbClsExtra = 0;
  100.     wc.cbWndExtra = 0;
  101.     wc.hInstance = hInst;
  102.     wc.hIcon = LoadIcon(hInst, "TermIcon");
  103.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  104.     wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  105.     wc.lpszMenuName =  "TermMenu";
  106.     wc.lpszClassName = "TermWClass";
  107.     Result = RegisterClass(&wc);
  108.     if(!Result) return FALSE;
  109.    }
  110.  
  111.  /* create main window */
  112.  hInstance = hInst;
  113.  hMainWnd = CreateWindow(
  114.    "TermWClass",   "Term",       WS_OVERLAPPEDWINDOW,
  115.    CW_USEDEFAULT,  CW_USEDEFAULT,
  116.    WinWidth,       WinHeight,
  117.    NULL,           NULL,
  118.    hInstance,      NULL);
  119.  ShowWindow(hMainWnd, nCmdShow);
  120.  UpdateWindow(hMainWnd);
  121.  
  122.  /* window control loop */
  123.  
  124.  while(GetMessage(&msg,NULL,0,0))
  125.    {
  126.     TranslateMessage(&msg);
  127.     DispatchMessage(&msg);
  128.    }
  129.  return (msg.wParam);
  130. } /* end WinMain */
  131.  
  132. #ifdef WIN32
  133. LRESULT CALLBACK
  134. #else
  135. long FAR PASCAL
  136. #endif
  137. MainWndProc(HWND hWindow,UINT iMsg,WPARAM wParam,LPARAM lParam)
  138. {int  i;
  139.  int  TheChar;
  140.  int  Count;
  141.  int  rc, Code;
  142.  HDC  hDC;
  143.  UINT idTimer;
  144.  PAINTSTRUCT ps;
  145.  static int mioState;
  146.  static int xyState;
  147.  hMainWnd = hWindow;
  148.  
  149.  switch (iMsg)
  150.     {
  151.      case WM_COMMAND:
  152.          switch(wParam)
  153.            {case MSG_ABOUT:
  154. #ifdef WIN32
  155.               DialogBox(hInstance,"AboutBox",hMainWnd,AboutDlgProc);
  156. #else
  157.               DialogBox(hInstance,"AboutBox",hMainWnd,lpfnAboutDlgProc);
  158. #endif
  159.               break;
  160.  
  161.             case MSG_BREAK:
  162.               mioState = 0;
  163.               xyState = 0;
  164.               mioBreak(ThePort);
  165.               xyAbort(ThePort);
  166.               DisableTheMenu(MSG_BREAK);
  167.               DrawMenuBar(hMainWnd);
  168.               break;
  169.  
  170.             case MSG_XM_RCV:
  171.               if(!StartXY(1,FileName)) break;
  172.               xyState = XM_RCV;
  173.               break;
  174.  
  175.             case MSG_XM_SND:
  176.               if(!StartXY(1,FileName)) break;
  177.               xyState = XM_SND;
  178.               break;
  179.  
  180.             case MSG_YM_RCV:
  181.               if(!StartXY(0,FileName)) break;
  182.               xyState = YM_RCV;
  183.               break;
  184.  
  185.             case MSG_YM_SND:
  186.               if(!StartXY(2,FileName)) break;
  187.               xyState = YM_SND;
  188.               break;
  189.  
  190.             case MSG_DIAL:
  191. #ifdef WIN32
  192.               DialogBoxParam(hInstance,"AcceptBox",hMainWnd,AcceptDlgProc,0);
  193. #else
  194.               DialogBoxParam(hInstance,"AcceptBox",hMainWnd,lpfnAcceptDlgProc,0);
  195. #endif
  196.               mioState = Dial_1;
  197.               break;
  198.  
  199.             case MSG_DEBUG:
  200.  
  201. #if 1
  202.               /* toggle debug level */
  203.               if(++DebugLevel>2) DebugLevel = 0;
  204.               xyDebug(DebugLevel);
  205.               wsprintf((LPSTR)Temp,"Debug level = %d", DebugLevel);
  206.               DisplayLine(Temp);
  207. #endif
  208.  
  209. #if 0
  210.               /* display seconds before expiration (SW only) */
  211.               wsprintf((LPSTR)Temp,"Expires in %d seconds", SioInfo('?') );
  212.               DisplayLine((LPSTR)Temp);
  213.               AnsiDebug(1);
  214. #endif
  215.               break;
  216.  
  217.             case MSG_STATUS:
  218.               while(xyGetMessage((LPSTR)MsgBuffer,80)) DisplayLine(MsgBuffer);
  219.               /* get state info */
  220. #if 0
  221.               wsprintf(Temp,"STATE=%d", (int)xyGetParameter(ThePort,XY_GET_STATE) );
  222.               DisplayLine(Temp);
  223. #endif
  224.               Code = (int) xyGetParameter(ThePort,XY_GET_ERROR_CODE);
  225.               if(Code)
  226.                 {wsprintf(Temp,"ERROR_CODE=%d", Code );
  227.                  DisplayLine(Temp);
  228.                  if(Code>=WSC_EXPIRED) SioError(Code,"");
  229.                  wsprintf(Temp,"ERROR_STATE=%d", (int)xyGetParameter(ThePort,XY_GET_ERROR_STATE) );
  230.                  DisplayLine(Temp);
  231.                 }
  232.               if(ThePort<0) break;
  233.               Code = SioStatus(ThePort, 0xFFFF);
  234.               /* framing error ? */
  235.               if((WSC_FRAME & Code) > 0) DisplayLine("[Framing error]");
  236.               /* overrun error ? */
  237.               if((WSC_OVERRUN & Code) > 0) DisplayLine("[Data overrun error]");
  238.               /* parity error ? */
  239.               if((WSC_PARITY & Code) > 0) DisplayLine("[Data parity error]");
  240.               /* RX overflow */
  241.               if((WSC_RXOVER & Code) > 0) DisplayLine("[Receive queue overflow]");
  242.               /* TX overflow */
  243.               if((WSC_TXFULL & Code) > 0) DisplayLine("[Transmit queue overflow]");
  244.               /* Show RX queue size */
  245.               Code = SioRxQue(ThePort);
  246.               if(Code>0)
  247.                 {wsprintf((LPSTR)Temp,"[RX queue size = %d]", Code);
  248.                  DisplayLine(Temp);
  249.                 }
  250.               /* Show TX queue size */
  251.               Code = SioTxQue(ThePort);
  252.               if(Code>0)
  253.                 {wsprintf((LPSTR)Temp,"[TX queue size = %d]", Code);
  254.                  DisplayLine(Temp);
  255.                 }
  256.               /* DSR status */
  257.               if(SioDSR(ThePort) > 0) DisplayLine("[DSR set]");
  258.               else DisplayLine("[DSR clear]");
  259.               /* CTS status */
  260.               if(SioCTS(ThePort) > 0) DisplayLine("[CTS set]");
  261.               else DisplayLine("[CTS clear]");
  262.               break;
  263.  
  264.             case MSG_ONLINE:
  265.               if(FatalFlag) ErrorMessage("Fatal Error");
  266.               else
  267.                 {/* try to go on-line */
  268.                  ThePort = GetPort();
  269.                  GoOnLine(ThePort,GetBaud(),2048,2048);
  270.                  DisplayLine("[Setting hardware flow control]");
  271.                  SioFlow(ThePort,'H');
  272.                  if(SioDSR(ThePort)==0) DisplayLine("[Waiting for DSR...]");
  273.                  if(SioCTS(ThePort)==0) DisplayLine("[Expecting CTS=1]");
  274.                  xyAcquire(ThePort);
  275.                  xyDebug(DebugLevel);
  276.                  SetTitle();
  277.                  CheckTheMenu(MSG_ONLINE);
  278.                  UncheckTheMenu(MSG_OFFLINE);
  279.                  EnableTheMenu(MSG_OFFLINE);
  280.                  DisableTheMenu(MSG_ONLINE);
  281.                  EnableTheMenu(MSG_DIAL);
  282.                  DisableMenuBarItem(MENU_BAR_CHANGE);
  283.                  EnableMenuBarItem(MENU_BAR_SEND);
  284.                  EnableMenuBarItem(MENU_BAR_RECEIVE);
  285.                  EnableMenuBarItem(MENU_BAR_STATUS);
  286.                  DrawMenuBar(hMainWnd);
  287.                 }
  288.               break;
  289.  
  290.             case MSG_OFFLINE:
  291.  
  292.               CheckTheMenu(MSG_OFFLINE);
  293.               UncheckTheMenu(MSG_ONLINE);
  294.               EnableTheMenu(MSG_ONLINE);
  295.               DisableTheMenu(MSG_OFFLINE);
  296.               DisableTheMenu(MSG_DIAL);
  297.               EnableMenuBarItem(MENU_BAR_CHANGE);
  298.               GoOffLine(ThePort);
  299.               xyRelease(ThePort);
  300.               SetTitle();
  301.               DisableMenuBarItem(MENU_BAR_SEND);
  302.               DisableMenuBarItem(MENU_BAR_RECEIVE);
  303.               DisableMenuBarItem(MENU_BAR_STATUS);
  304.               DrawMenuBar(hMainWnd);
  305.               break;
  306.  
  307.             case MSG_EXIT:
  308.               GoOffLine(ThePort);
  309.               KillTimer(hMainWnd,idTimer);
  310.               PostQuitMessage(0);
  311.               break;
  312.  
  313.             case MSG_110:
  314.               SetBaud(Baud110);
  315.               break;
  316.  
  317.             case MSG_300:
  318.               SetBaud(Baud300);
  319.               break;
  320.  
  321.             case MSG_1200:
  322.               SetBaud(Baud1200);
  323.               break;
  324.  
  325.             case MSG_2400:
  326.               SetBaud(Baud2400);
  327.               break;
  328.  
  329.             case MSG_4800:
  330.               SetBaud(Baud4800);
  331.               break;
  332.  
  333.             case MSG_9600:
  334.               SetBaud(Baud9600);
  335.               break;
  336.  
  337.             case MSG_19200:
  338.               SetBaud(Baud19200);
  339.               break;
  340.  
  341.             case MSG_38400:
  342.               SetBaud(Baud38400);
  343.               break;
  344.  
  345.             case MSG_57600:
  346.               SetBaud(Baud57600);
  347.               break;
  348.  
  349.             case MSG_COM1:
  350.               SetThePort(COM1);
  351.               break;
  352.  
  353.             case MSG_COM2:
  354.               SetThePort(COM2);
  355.               break;
  356.  
  357.             case MSG_COM3:
  358.               SetThePort(COM3);
  359.               break;
  360.  
  361.             case MSG_COM4:
  362.               SetThePort(COM4);
  363.               break;
  364.  
  365.             case MSG_NONE:
  366.               SetParity(NoParity);
  367.               break;
  368.  
  369.             case MSG_EVEN:
  370.               SetParity(EvenParity);
  371.               break;
  372.  
  373.             case MSG_ODD:
  374.               SetParity(OddParity);
  375.               break;
  376.  
  377.             case MSG_1_SB:
  378.               SetStopBits(OneStopBit);
  379.               break;
  380.  
  381.             case MSG_2_SB:
  382.               SetStopBits(TwoStopBits);
  383.               break;
  384.  
  385.             case MSG_7_DB:
  386.               SetWordLength(WordLength7);
  387.               break;
  388.  
  389.             case MSG_8_DB:
  390.               SetWordLength(WordLength8);
  391.               break;
  392.  
  393.             default:
  394.               return (DefWindowProc(hMainWnd, iMsg, wParam, lParam));
  395.            }
  396.          break;
  397.  
  398.     case WM_CREATE:
  399.  
  400.       /* check "OFFLINE" menu item */
  401.       CheckTheMenu(MSG_OFFLINE);
  402.       DisableTheMenu(MSG_OFFLINE);
  403.       DisableTheMenu(MSG_BREAK);
  404.       DisableTheMenu(MSG_DIAL);
  405.       DisableMenuBarItem(MENU_BAR_SEND);
  406.       DisableMenuBarItem(MENU_BAR_RECEIVE);
  407.       DisableMenuBarItem(MENU_BAR_STATUS);
  408. #ifdef WIN32
  409. #else
  410.       /* create AboutDlgProc() thunk */
  411.       lpfnAboutDlgProc = MakeProcInstance(AboutDlgProc, hInstance);
  412.       /* create AcceptDlgProc() thunk */
  413.       lpfnAcceptDlgProc = MakeProcInstance(AcceptDlgProc, hInstance);
  414. #endif
  415.       /* initialize paint module */
  416.       PaintInit();
  417.       /* init configuration */
  418.       CheckAll();
  419.       SetText((LPSTR)"TERM");
  420.       SetTitle();
  421.       /* start timer */
  422.       idTimer = SetTimer(hMainWnd,1,250,NULL);
  423.       if(idTimer==0)
  424.          {ErrorMessage("No timers remaining !");
  425.           FatalFlag = TRUE;
  426.          }
  427.       DrawMenuBar(hMainWnd);
  428.       break;
  429.  
  430.     case WM_KEYDOWN:
  431.       switch(wParam)
  432.         {case VK_UP:
  433.            AnsiUp(ThePort);
  434.            break;
  435.          case VK_DOWN:
  436.            AnsiDown(ThePort);
  437.            break;
  438.          case VK_RIGHT:
  439.            AnsiRight(ThePort);
  440.            break;
  441.          case VK_LEFT:
  442.            AnsiLeft(ThePort);
  443.            break;
  444.         }
  445.       break;
  446.  
  447.     case WM_CHAR:
  448.       /* send char to port */
  449.       SioPutc(ThePort, (char)wParam );
  450.       break;
  451.  
  452.     case WM_TIMER:
  453.       /* fatal error ? */
  454.       if(FatalFlag) break;
  455.       if(!OnLineFlag) break;
  456.  
  457.       /* check xyDriver */
  458.       if(xyState)
  459.         {switch(xyState)
  460.            {case XM_RCV:
  461.               /* XMODEM receive */
  462.               if(xyStartRx(ThePort,FileName,NAK,FALSE))
  463.                  {DisplayLine("XMODEM Rx started");
  464.                   xyState = XY_MODEM;
  465.                  }
  466.               else
  467.                  {DisplayLine("Could not start RX");
  468.                   xyState = 0;
  469.                  }
  470.               break;
  471.             case XM_SND:
  472.               /* XMODEM send */
  473.               if(xyStartTx(ThePort,FileName,FALSE,FALSE))
  474.                  {DisplayLine("XMODEM Tx started");
  475.                   xyState = XY_MODEM;
  476.                  }
  477.               else
  478.                  {DisplayLine("Could not start TX");
  479.                   xyState = 0;
  480.                  }
  481.               break;
  482.             case YM_RCV:
  483.               /* YMODEM receive */
  484.               *FileName = '\0';
  485.               if(xyStartRx(ThePort,FileName,'C',TRUE))
  486.                  {DisplayLine("YMODEM Rx started");
  487.                   xyState = XY_MODEM;
  488.                  }
  489.               else
  490.                  {DisplayLine("Could not start RX");
  491.                   xyState = 0;
  492.                  }
  493.               break;
  494.             case YM_SND:
  495.               /* YMODEM send */
  496.               if(xyStartTx(ThePort,FileName,TRUE,TRUE))
  497.                  {DisplayLine("YMODEM Tx started");
  498.                   xyState = XY_MODEM;
  499.                  }
  500.               else
  501.                  {DisplayLine("Could not start TX");
  502.                   xyState = 0;
  503.                  }
  504.               break;
  505.             case XY_MODEM:
  506.               /* run the driver */
  507.               rc = xyDriver(ThePort);
  508.               /* look at any messages */
  509.               while(xyGetMessage((LPSTR)MsgBuffer,80)) DisplayLine(MsgBuffer);
  510.               if(*MsgBuffer=='!') rc = XY_IDLE;
  511.               /* XMODEM or YMODEM in progress ? */
  512.               if(rc==XY_IDLE)
  513.                 {/* XY send/receive complete */
  514.                  DisplayLine("XMODEM/YMODEM is done.");
  515.                  DisableTheMenu(MSG_BREAK);
  516.                  DrawMenuBar(hMainWnd);
  517.                  xyState = 0;
  518.                  break;
  519.                 }
  520.               /* XMODEM / YMODEM is still running */
  521.               ShowProgress();
  522.               break;
  523.            } /* end-switch */
  524.          break;
  525.         } /* end-if(xyState) */
  526.  
  527.       /* xyDriver is not running */
  528.       if(mioState)
  529.         {/* MIO is running ! */
  530.          rc = mioDriver(ThePort);
  531.          if(rc==MIO_IDLE)
  532.            {/* time to go to next MIO state (since driver is idle) */
  533.             switch(mioState)
  534.               {case Dial_1:
  535.                  /* fetch dial string */
  536.                  if(GetAcceptText((LPSTR)Temp))
  537.                    {/* dial modem */
  538.                     lstrcpy((LPSTR)DialString,"ATDT");
  539.                     lstrcat((LPSTR)DialString,Temp);
  540.                     lstrcat((LPSTR)DialString,"!");
  541.                     DisplayLine(DialString);
  542.                     EnableTheMenu(MSG_BREAK);
  543.                     DrawMenuBar(hMainWnd);
  544.                     mioSendTo(ThePort, 125, DialString);
  545.                     mioState = Dial_2;
  546.                    }
  547.                  else
  548.                    {DisplayLine("Missing phone number!");
  549.                     mioState = 0;
  550.                    }
  551.                  break;
  552.                case Dial_2:
  553.                  /* expect "CONNECT" back (wait up to 60 seconds) */
  554.                  if(mioWaitFor(ThePort, 60000, "CONNECT")) mioState = Dial_3;
  555.                  else DisplayString (">>>mioWaitFor fails!");
  556.                  break;
  557.                case Dial_3:
  558.                  /* did we get expected result ("CONNECT") */
  559.                  if(mioResult(ThePort)) DisplayString (">>>CONNECT was received");
  560.                  else DisplayString (">>>CONNECT was NOT received!");
  561.                  /* all done */
  562.                  DisableTheMenu(MSG_BREAK);
  563.                  DrawMenuBar(hMainWnd);
  564.                  mioState = 0;
  565.                } /* end-switch */
  566.             }
  567.          else
  568.            {/* MIO is not IDLE */
  569.             if(rc != MIO_RUNNING) DisplayChar((char)rc);
  570.            } /* end-if(mioState) */
  571.          break;
  572.         }
  573.       /* AnsiGetc() may return cursor status report */
  574.       while((i = AnsiGetc()) >= 0) SioPutc(ThePort, (char)i);
  575.       /* neither xyDriver nor MIO is running */
  576.       Count = 0;
  577.       /* fetch line of up to 1024 chars */
  578.       for(i=0;i<1024;i++)
  579.         {TheChar = SioGetc(ThePort);
  580.          /* character available ? */
  581.          if(TheChar==WSC_NO_DATA) break;
  582.          AnsiPutc((char)TheChar);
  583.         } /* end while */
  584.       break;
  585.  
  586.     case WM_SETFOCUS:
  587.       /* create client area caret */
  588.       CreateCaret(hMainWnd,NULL,3,10);
  589.       SetCaretPos(PaintGetColPos(),PaintGetRowPos());
  590.       ShowCaret(hMainWnd);
  591.       break;
  592.  
  593.     case WM_KILLFOCUS:
  594.       DestroyCaret();
  595.       break;
  596.  
  597.     case WM_PAINT:
  598.       HideCaret(hMainWnd);
  599.       hDC = BeginPaint(hMainWnd, &ps);
  600.       SetMapMode(hDC,MM_ANISOTROPIC);
  601.       SelectObject(hDC, GetStockObject(OEM_FIXED_FONT) );
  602.       PaintMain(hDC,&ps);
  603.       EndPaint(hMainWnd,&ps);
  604.       SetCaretPos(PaintGetColPos(),PaintGetRowPos());
  605.       ShowCaret(hMainWnd);
  606.       break;
  607.  
  608.     case WM_DESTROY:
  609.       GoOffLine(ThePort);
  610.       if(idTimer) KillTimer(hMainWnd,idTimer);
  611.       PostQuitMessage(0);
  612.       break;
  613.  
  614.     default:
  615.       return (DefWindowProc(hMainWnd, iMsg, wParam, lParam));
  616.    }
  617.  return 0;
  618. } /* end MainWndProc */
  619.  
  620. void ErrorCheck(int Code)
  621. {/* trap PCL error codes */
  622.  if(Code<0)
  623.    {SioError(Code,"Sio Error");
  624.     SioDone(GetPort());
  625.     FatalFlag = TRUE;
  626.    }
  627. }
  628.  
  629. void ErrorMessage(LPSTR MsgPtr)
  630. {
  631.  MessageBox(hMainWnd,MsgPtr,"ERROR",MB_ICONEXCLAMATION | MB_OK);
  632. }
  633.  
  634. void ShowProgress(void)
  635. {int Packet;
  636.  static int LastPacket = -1;
  637.  while(xyGetMessage((LPSTR)MsgBuffer,80)) DisplayLine(MsgBuffer);
  638.  Packet = (int) xyGetParameter(ThePort,XY_GET_PACKET);
  639.  if(Packet!=LastPacket)
  640.    {/* new packet number */
  641.     LastPacket = Packet;
  642.     if(DebugLevel==0)
  643.       {wsprintf((LPSTR)Temp,"Packet %d \r",Packet);
  644.        DisplayString(Temp);
  645.       }
  646.    }
  647. }
  648.  
  649. int StartXY(int Choice, LPSTR FileName)
  650. {if(!OnLineFlag)
  651.    {DisplayLine("Must be online!");
  652.     return FALSE;
  653.    }
  654.  if(xyGetParameter(ThePort,XY_GET_STATE)==(long)XY_RUNNING)
  655.    {DisplayLine("xyDriver already running!");
  656.     return FALSE;
  657.    }
  658.  if(Choice)
  659.    {/* get file name from user */
  660. #ifdef WIN32
  661.     DialogBoxParam(hInstance,"AcceptBox",hMainWnd,AcceptDlgProc,Choice);
  662. #else
  663.     DialogBoxParam(hInstance,"AcceptBox",hMainWnd,lpfnAcceptDlgProc,Choice);
  664. #endif
  665.     if(GetAcceptText((LPSTR)FileName)) DisplayLine(FileName);
  666.     else
  667.       {DisplayLine("Missing filename");
  668.        return FALSE;
  669.       }
  670.    }
  671.  EnableTheMenu(MSG_BREAK);
  672.  DrawMenuBar(hMainWnd);
  673.  return TRUE;
  674. }
  675.                                                                                                                                                                                                                                                                                                  
  676.